﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenSoftStore.BusinessLogic.Common;
using OpenSoftStore.BusinessLogic.Product;
using OpenSoftStore.Client.Common;

namespace OpenSoftStore.Client.UIL.ManageReport
{
    public partial class ReportStoreIO : UserControl
    {

        public ProductLogic LgcProduct;
        public ComboLogic LgcCombo;
        public ReportStoreIO()
        {
            InitializeComponent();
            LgcProduct=new ProductLogic();
            dgvStoreGroup.AutoGenerateColumns = false;
            dgvStoreIOItem.AutoGenerateColumns = false;
            LgcCombo=new ComboLogic();
            var stores = LgcCombo.GetComboByBuzType("Pos", "b0def1a7-bf25-45f2-b65a-6dc586dbfc2c").ToList();
            dgvCmbStore.DataSource = stores;
            dgvCmbStore.DisplayMember = "DisplayText";
            dgvCmbStore.ValueMember = "Value1";
            if (stores.Any())
                dgvCmbStore.DefaultCellStyle.NullValue = stores[0].DisplayText;
            SPACommon.SetDataGridStyle(dgvStoreGroup);
            SPACommon.ShowSummary(dgvStoreGroup);
            SPACommon.SetDataGridStyle(dgvStoreIOItem);
            //SPACommon.ShowSummary(dgvStoreIOItem);

        }

        private static ReportStoreIO instance;
        public static ReportStoreIO Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ReportStoreIO();
                }
                return instance;
            }
        }

        private void btnOutput_Click(object sender, EventArgs e)
        {
            SPACommon.ExportToExcel(dgvStoreGroup, "库存进出情况统计");
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            DateTime from = dtpFrom.Value.Date;
            DateTime to = dtpTo.Value.Date.AddDays(1).AddSeconds(-1.0);
            var name = txtName.Text;
            string where =
                 string.Format(" where (t5.Name like '%{0}%' )", name);
            dgvStoreGroup.DataSource = LgcProduct.GetStoreIoDataTable(from, to, where);
            SPACommon.SetDataGridStyle(dgvStoreGroup);
            SPACommon.ShowSummary(dgvStoreGroup);
        }

        private void dgvStoreGroup_SelectionChanged(object sender, EventArgs e)
        {
            DateTime from = dtpFrom.Value.Date;
            DateTime to = dtpTo.Value.Date.AddDays(1).AddSeconds(-1.0);
            if (dgvStoreGroup.CurrentRow == null) return;
            var productId = dgvStoreGroup.CurrentRow.Cells["ProductId"].Value.ToString();
            dgvStoreIOItem.DataSource = LgcProduct.GetStoreIoItemDataTable(from, to, productId);
            SPACommon.SetDataGridStyle(dgvStoreIOItem);
            SPACommon.ShowSummary(dgvStoreIOItem);
        }

    }
}
